/*
 * rtc_hal.h
 *
 *  Created on: Sep 18, 2013
 *      Author: Ken Arok
 */

#include "config_board.h"

#if BOARD_2_1_USED

#ifndef RTC_HAL_H_
#define RTC_HAL_H_

#include <compiler.h>

#ifdef __cplusplus
extern "C" {
#endif

// TWI data transfer rate
#define TWI_SPEED						100000
// TWI RTC Slave Address
#define TWI_RTC_SLAVE_ADDRESS			(0xD0)	//! DS1307 Slave Address

// DS1307 RTC Memory Address
#define VL_SECOND_ADDR		0x00
#define MINUTES_ADDR		0x01
#define HOURS_ADDR			0x02
#define WEEKDAYS_ADDR		0x03
#define DAYS_ADDR			0x04
#define CENTURY_MONTH_ADDR	0x05
#define YEARS_ADDR			0x06
#define CLKOUT_CTRL_ADDR	0x07
#define TIMER_CTRL_ADDR		0x08	//! Compatibility only


typedef struct {
	uint8_t seconds;
	uint8_t minutes;
	uint8_t hours;
	uint8_t days;
	uint8_t weekdays;
	uint8_t months;
	uint8_t years;
}rtc_raw_t;



/** \brief Write calender value to RTC chip register.
 *
 * \param _rtc	Pointer to RTC raw structure.
 *
 */
extern void rtc_write_calendar(rtc_raw_t *_rtc);

/** \brief Read calender value from RTC chip register.
 *
 * \param _rtc	Pointer to RTC raw structure where RTC value will be copied.
 *
 */
extern void rtc_read_calendar(rtc_raw_t *_rtc);

/** \brief Read the CTRL status register of PCF8563.
 *
 * \return CTRL_VAL		Value of CTRL register.
 *
 */
extern uint8_t rtc_read_ctrl(void);

#ifdef __cplusplus
}
#endif

#endif /* RTC_HAL_H_ */

#endif /* BOARD_2_1_USED */
